import 'package:flutter/material.dart';

class CustomButton extends StatelessWidget {
  final VoidCallback onTap;
  final String text;
  final String imagePath;
  final double width;
  final double height;
  final TextStyle style;

  /**
   * 自定义按钮
   * @param onTap 点击事件
   * @param text 按钮文字
   * @param imagePath 按钮背景图片
   * @param width 按钮宽度
   * @param height 按钮高度
   * @param style 按钮文字样式
   */
  CustomButton({
    required this.onTap,
    required this.text,
    required this.imagePath,
    this.width = 120.0,
    this.height = 40.0,
    this.style = const TextStyle(
      color: Colors.white,
      fontWeight: FontWeight.bold,
    ),
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      width: width,
      height: height,
      decoration: BoxDecoration(
        image: DecorationImage(
          image: AssetImage(imagePath),
        ),
      ),
      child: GestureDetector(
        onTap: onTap,
        child: Center(
          child: Text(
            text,
            textAlign: TextAlign.center,
            style: style,
          ),
        ),
      ),
    );
  }
}